package com.thoughtworks;

import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;

import java.util.Scanner;

public class Main {



public static int swValue, n,checkout=0,k=-1,j=0,len;
    public static String[] checkedoutbooks=new String[10];
    public static Scanner scn;
    public  static    String name="";
    public static int menuoption(){
        System.out.println();
        System.out.println("| Options:                   |");
        System.out.println("|        1. checkout         |");
        System.out.println("|        2. return           |");
        scn = new Scanner(System.in);
        System.out.println();
        System.out.println("select option");
        swValue = scn.nextInt();

        return swValue;
    }
public static void switchcase(int s,book books[])
{
    switch(swValue) {
        case 1:scn = new Scanner(System.in);
            System.out.println("enter the book to checkout");
            name = scn.nextLine();
            int ret1=bookcheckout.checkout(books,name);
            if (ret1 == 1)
                System.out.println("Thank you enjoy the book");
            else
                System.out.println("That book is not available");
            break;
        case 2:System.out.println("enter the book name you want to return");
            scn = new Scanner(System.in);
            name = scn.nextLine();
           int ret2= bookreturn.returnedbook(books,name);
            if(ret2==1)
                System.out.println("return successfull");
            else
                System.out.println("return unsuccessfull");
            break;
    }
}
    public static void displaybooks(book books[]){
        for (int i = 0; i < books.length; i++) {
            System.out.println();
            System.out.format("%-50s%-50s%-50d",books[i].bookname,books[i].author,books[i].yop);
            }
    }
    public static void main(String[] args) {


        int m = 1,flag=0;
        book[] books = new book[3];
        books[0]=new book("head first java","robert",2012);
        books[1]=new book("let us C","yashwanth",2014);
        books[2]=new book("operating system","gayle",2011);
        System.out.println("============================= ");
        System.out.println("|         WELCOME            |");
        System.out.println("============================= ");
        System.out.println("| Options:                   |");
        System.out.println("|        1. list books       |");
        System.out.println("|        2. quit             |");
        System.out.println("============================= ");
       while (m == 1) {
           scn = new Scanner(System.in);
           System.out.println("select option");
           swValue = scn.nextInt();
        switch(swValue){
            case 1:if(checkout==0) {
                       System.out.format("%-50s%-50s%-50s","book name","author","year of publication");
                        displaybooks(books);
                        int swv=menuoption();
                        switchcase(swv,books);
                  }else {
                System.out.format("%-50s%-50s%-50s","book name","author","year of publication");

                for (int i = 0; i < books.length; i++) {
                    for (int j = 0; j <= k; j++) {
                        if (checkedoutbooks[j].equals(books[i].bookname))
                            flag = 1;
                    }

                    if (flag == 0) {
                        System.out.println();
                        System.out.format("%-50s%-50s%-50d",books[i].bookname,books[i].author,books[i].yop);
                    }
                    flag = 0;
                }
                int swv = menuoption();
                switchcase(swv, books);
            }
                  break;
            case 2:System.exit(0);
            default:
                System.out.println("enter a valid choice");

        }
        }
    }
}